package cn.hotel.controller.worker;

import cn.hotel.entity.Room;
import cn.hotel.response.ResponseTool;
import cn.hotel.response.Result;
import cn.hotel.service.RoomService;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping(value = "/op/room")
public class OpRoomController {

    @Autowired
    private RoomService roomService;

    /**
     * 获取所有的房间信息
     * @return
     */
//    @PostMapping()
//    public Result getAllRoomInfo(){
//        List<Room> roomInfo = roomService.queryAllRoomInfo();
//        return ResponseTool.success(roomInfo);
//    }

    /**
     * 分页查询
     * 获取所有的房间信息
     * @return
     */
    @PostMapping("/list")
    public Result getAllRoomInfo(Integer page , Integer pageSize){
        PageInfo<Room> pageInfo = roomService.queryList(page, pageSize);
        return ResponseTool.success(pageInfo);
    }

    /**
     * 添加房间信息
     * @param room
     * @return
     */
    @PostMapping("/add")
    public Result addRoom(Room room){
        roomService.insertRoom(room);
        return ResponseTool.success("房间信息添加成功");
    }

    /**
     * 查询房间信息
     * @param roomId
     * @return
     */
    @PostMapping("/{roomId}")
    public Result getRoomInfo(@PathVariable("roomId") int roomId){
        Room room = roomService.queryRoomInfoByRoomId(roomId);
        return ResponseTool.success(room);
    }

    /**
     * 更新房间信息
     */
    @PostMapping("/update")
    public Result changeRoomInfo(Room room){
        roomService.updateRoomInfo(room);
        return ResponseTool.success("更新房间信息成功");
    }

    /**
     * 删除房间信息
     */
    @DeleteMapping("/delete")
    public Result removeRoomInfo(@RequestParam("roomIds") List<Integer> roomIds){
        log.info("roomIds:{}",roomIds);
        for (Integer roomId : roomIds) {
            roomService.deleteRoomByRoomId(roomId);
        }
        return ResponseTool.success("删除成功");
    }
}
